package com.h3c.gm.service

import com.google.common.collect.Lists
import com.google.common.collect.Maps
import com.h3c.gm.dao.IBusOrgDao
import com.h3c.gm.dao.IBusUserDao
import com.h3c.gm.entity.DO.BusUserDO
import org.springframework.stereotype.Service

import javax.annotation.Resource

/**
 * Created by d14287 on 2017/6/26.
 */
@Service
class BusUserService {
    @Resource
    IBusUserDao busUserDao
    @Resource
    IBusOrgDao busOrgDao

    int getCount() {
        busUserDao.getCount(Maps.newHashMap())
    }

    int getOrgCount(String orgkey) {
        def queryParams = Maps.newHashMap()
        def orgkeyList = Lists.newArrayList()
        orgkeyList.add(orgkey)
        queryParams.put('orgkeyList', orgkeyList)
        busUserDao.getCount(queryParams)
    }

    int getProCount(String province) {
        def orgkeyList = getOrgkeyList(province)
        def queryParams = Maps.newHashMap()
        queryParams.put('orgkeyList', orgkeyList)
        busUserDao.getCount(queryParams)
    }

    List<Map<String, Object>> getStatistics(Date from, Date to) {
        def queryParams = Maps.newHashMap()
        queryParams.put('from', from)
        queryParams.put('to', to)

        busUserDao.getStatistics(queryParams)

    }

    List<Map<String, Object>> getProStatistics(Date from, Date to, String province) {
        def orgkeyList = getOrgkeyList(province)
        def queryParams = Maps.newHashMap()
        queryParams.put('orgkeyList', orgkeyList)
        queryParams.put('from', from)
        queryParams.put('to', to)
        busUserDao.getStatistics(queryParams)
    }

    void insert(BusUserDO busUserDO) {
        busUserDao.insert(busUserDO)
    }

    List<String> getOrgkeyList(String province) {
        def busOrgDOs = busOrgDao.getCityOrg(province)
        def orgkeys = Lists.newArrayList()
        busOrgDOs.each {
            item ->
                orgkeys.add(item.getOrgkey())
        }
        return orgkeys
    }

    void deleteByOrgkey(String orgkey) {
        busUserDao.deleteByOrgkey(orgkey)
    }

}
